package com.gx.smart.building.ui.message.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.TimeUtils;
import com.gx.smart.base.BaseAdapter;
import com.gx.smart.building.R;
import com.gx.smart.building.databinding.ItemMessageBinding;
import com.gx.smart.lib.http.api.response.Message;

/**
 * @author: xiaosy
 * 时间: 2022/4/7
 * @Description: java类作用描述
 * @Version: 1.0
 **/
public class MessageAdapter extends BaseAdapter<Message, MessageAdapter.ViewHolder> {
    public MessageAdapter(Context context) {
        super(context);
    }

    @Override
    protected int onBindLayout() {
        return R.layout.item_message;
    }

    @Override
    protected ViewHolder onCreateHolder(View view) {
        ItemMessageBinding binding = ItemMessageBinding.inflate(LayoutInflater.from(mContext),
                (ViewGroup) view, false);
        return new ViewHolder(binding);
    }

    @Override
    protected void onBindData(ViewHolder holder, Message item, int position) {
        holder.binding.title.setText(item.getTitle());
        //是否已读，1是 2否
        holder.binding.isRead.setVisibility(item.isRead() == 1 ? View.GONE : View.VISIBLE);
        String time = TimeUtils.millis2String(Long.parseLong(item.getCreateTime()),
                "yyyy-MM-dd HH:mm:ss");
        holder.binding.createTime.setText(time);
    }

    protected static class ViewHolder extends RecyclerView.ViewHolder {
        private final ItemMessageBinding binding;

        public ViewHolder(ItemMessageBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}
